<template>
    <rx-dialog @handOk="handleSubmit" @cancel="cancel">
        <rx-layout>
            <div slot="center">
                <a-form :form="form" class="editforms">
                    <a-form-item style="display:none">
                        <a-input v-decorator="['dimId']"/>
                    </a-form-item>
                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.dimensionName','维度名称')">
                        <rx-input-i18n :placeholder="i18n('form.dimensionName','维度名称')" :isDecorator="true"
                                     v-decorator="['i18nJson', {rules: [{required: true, message: i18n('form.dimensionName','维度名称','input')}]}]"
                        />
                    </a-form-item>
                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.encoded','编码')">
                        <a-input
                            :placeholder="i18n('form.encoded','编码')"
                            v-decorator="['code', {rules: [{required: true, message: i18n('form.encoded','编码','input')}]}]"
                        />
                    </a-form-item>
                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.status','状态')">
                        <a-radio-group
                            buttonStyle="solid"
                            :placeholder="i18n('form.status','状态')"
                            v-decorator="['status', {initialValue:'ENABLED',rules: [{required: true, message: i18n('form.status','状态','input')}]}]"
                        >
                            <a-radio-button value="ENABLED">{{i18n('statusMap.startUsing','状态') }}</a-radio-button>
                            <a-radio-button value="DISABLED">{{i18n('statusMap.forbidden','状态') }}</a-radio-button>
                        </a-radio-group>
                    </a-form-item>
                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.presentationType','展示类型')">
                        <a-radio-group
                            @change="dataPresentationType"
                            buttonStyle="solid"
                            :placeholder="i18n('form.dataPresentationType','数据展示类型')"
                            v-decorator="['showType', {initialValue:'FLAT',rules: [{required: true, message: i18n('form.dataPresentationType','数据展示类型','input')}]}]"
                        >
                            <a-radio-button value="FLAT">{{i18n('dataPresentationTypeMap.tile','数据展示类型') }}</a-radio-button>
                            <a-radio-button value="TREE">{{i18n('dataPresentationTypeMap.tree','数据展示类型') }}</a-radio-button>
                        </a-radio-group>
                    </a-form-item>
                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.joinEmpower','参与授权')">
                        <a-radio-group
                            buttonStyle="solid"
                            :placeholder="i18n('form.joinEmpower','参与授权')"
                            v-decorator="['isGrant',{initialValue:'YES'}]"
                        >
                            <a-radio-button value="YES">{{i18n('isJoinEmpowerMap.yes','是否参与授权') }}</a-radio-button>
                            <a-radio-button value="NO">{{i18n('isJoinEmpowerMap.no','是否参与授权') }}</a-radio-button>
                        </a-radio-group>
                    </a-form-item>
                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.sortNumber','排序号')">
                        <a-input-number
                            :maxValue="100000"
                            :minValue="0"
                            :placeholder="i18n('form.sortNumber','排序号')"
                            v-decorator="['sn', {initialValue:1,rules: [{required: true, message: i18n('form.sortNumber','排序号','input')}]}]"
                        />
                    </a-form-item>
                    <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" :label="i18n('form.describe','描述')">
                        <a-textarea :placeholder="i18n('form.describe','描述')" style="height:50px;" v-decorator="['desc']"/>
                    </a-form-item>
                </a-form>
            </div>
        </rx-layout>
    </rx-dialog>
</template>
<script>
    import OsDimensionApi from '@/api/user/org/osDimension'
    import {BaseForm, RxDialog} from "@lowcode/jpaas-common-lib";

    export default {
        name: 'OsDimensionEdit',
        mixins: [BaseForm],
        components: {
            RxDialog,
        },
        data() {
            return {
                visible: false,
                confirmLoading: false,
                mdl: {},
                title: '',
                labelCol: {span: 5},
                wrapperCol: {span: 16},
            }
        },
        methods: {
            dataPresentationType(selectedValue){
                //获取当前dimId，如果为角色或者职务则不允许改成树类型
                var dimId = this.form.getFieldValue('dimId')
                if(2 == dimId || 3 == dimId){
                    selectedValue.target.value = "FLAT"
                }

            },
            i18n(name, text, key) {
                return this.$ti18(name, text, "osDimension", key);
            },
            get(id) {
                return OsDimensionApi.get(id);
            },
            save(values) {
                return OsDimensionApi.save(values);
            }
        },
    }
</script>
<style scoped>
    .editforms >>> .ant-row.ant-form-item:last-child {
        margin-bottom: 0;
    }
</style>